package Thread;

/**
 * @author liyang
 * @version 1.0
 * @package Thread
 * @file SyncDemo3.java
 * @description
 * @time 2024-04-12 14:12
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1 = new Foo();
        Foo f2 = new Foo();
        Thread t1 = new Thread(){
            @Override
            public void run(){
                Foo.dosome();
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run(){
                Foo.dosome();
            }
        };

        t1.start();
        t2.start();
    }
}
class Foo{
//    public  synchronized  static void dosome(){
    public  static void dosome(){

        /*try快捷键：选中ctrl + alt + t*/
        try {
            Thread t = Thread.currentThread();
            synchronized (Foo.class) {
                System.out.println(t.getName() + "执行..");
                Thread.sleep(5000);
            }
            System.out.println("执行完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
